package com.jax.pronet.xml;

import com.jax.pronet.bo.Network;
import com.jax.pronet.bo.Programmer;
import com.jax.pronet.bo.Recommendation;
import com.jax.pronet.bo.Skill;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.io.IOException;

/**
 * User: Lucy
 * Date: 15/10/12
 * Time: 14:05
 */
public class NetworkLoader
{
  
  public Network loadNetwork() throws IOException {
    try
    {
    JAXBContext c = JAXBContext.newInstance(Network.class, Programmer.class, Recommendation.class, Skill.class);
     Marshaller m = c.createMarshaller();
    Unmarshaller u  = c.createUnmarshaller();
    
    Network n = (Network) u.unmarshal(this.getClass().getClassLoader().getResource("com/jax/pronet/xml/ProNet.xml"));
    //Network n = (Network) u.unmarshal(new File(new File("com/jax/pronet/xml/"), "ProNet.xml"));
    return n;
    }
    catch(JAXBException eJAXB) {
      throw new IOException("Failed to load Network", eJAXB);
    }
  }
  
}
